<?php include  APP_PATH.'../template/public/header.php'?>
<aside class="main-sidebar">
    <section class="sidebar">
        <?php include APP_PATH.'../template/public/navigation.php'?>
    </section>
</aside>
<div class="content-wrapper">
    <section class="content-header">
        <h1>
            {$title}
            <a href="{:url('add_agent_user')}" class="btn btn-info">添加代理商账号</a>
        </h1>

        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> {$title}</a></li>
        </ol>
    </section>
    <section class="content">

        <div class="box">

            <div class="box-body">
                <div class="input-daterange input-group">


                </div>
                <table id='table'
                       data-url="{:url('get_agent_list')}"
                       data-toggle="table"
                       data-show-refresh="true"
                       data-show-toggle="true"
                       data-show-columns="true"
                       data-search="true"
                       data-pagination="true"
                       data-query-params="queryParams"
                       data-advanced-search="true"
                       data-side-pagination="server"
                       data-select-item-name="worker_picker"
                       data-show-export="true"
                       data-click-to-select="true"
                       data-toolbar="#toolbar"
                       data-sort-name="name"
                       data-sort-order="desc">
                    <div class="bars pull-left">
                        <div id="toolbar">

                        </div>
                    </div>
                    <thead>
                    <tr>
                        <th data-field="name"  data-align="left" data-sortable="true" >用户名</th>
                        <th data-field="agent_name"  data-align="left" data-sortable="true" >代理商名称</th>
                        <th data-field="company_name"   data-align="left">公司名称</th>
                        <th data-field="contact"   data-align="left">联系人</th>
                        <th data-field="contact_phone"   data-align="left">联系电话</th>
                        <th data-field="audit_state"   data-align="left">审核状态</th>
                        <th data-field="audit_note"   data-align="left">审核信息</th>
                        <th data-field="operation"   data-align="left">操作</th>
                    </tr>

                    </thead>
                    <tbody>
                    </tbody>
                </table>
            </div>
        </div>
    </section>
    <div class="modal fade bs-example-modal-sm" id='edit_worker'>
        <div class="modal-dialog modal-sm">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title">账户充值</h4>
                </div>
                <div class="modal-body">
                    <form id="form1">
                        <!-- text input -->
                        <div class="form-group">
                            <input type="hidden" class="form-control" name='user_id' id='user_id'/>
                            <input type="hidden" class="form-control" name='operation_user_id' id='operation_user_id'/>
                            <label>用户名</label>
                            <input type="text" class="form-control" name='username' id='username' disabled/>
                        </div>
                        <div class="form-group">
                            <label>当前余额</label>
                            <input type="text" class="form-control"  id='amount' disabled/>
                        </div>
                        <div class="form-group">
                            <label>充值金额</label>
                            <input type="text" class="form-control" name='recharge_amount' id='recharge_amount' value="0"/>
                        </div>
                        <div class="form-group">
                            <label>充值方式</label>
                            <select class="form-control" name='recharge_type' id='recharge_type'>
                                <option value='3' selected="selected">支付宝</option>
                                <option value='4' selected="selected">微信</option>
                                <option value='5' selected="selected">转账</option>
                            </select>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-default pull-left" data-dismiss="modal">关闭</button>
                            <button  type="button" id="submit_updata" class="btn btn-primary" >充值</button>
                        </div>
                    </form>
                </div>
            </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
    </div><!-- /.modal -->
</div>
<?php include APP_PATH.'../template/public/footer.php'; ?>
<script>

    function queryParams(params) {
        return {
            limit: params.limit,
            offset: params.offset,
            search:$('.search input[type="text"]').val(),
            name: params.sort,
            order: params.order,

        };
    }
    function cancel_aduit(id) {
        var loading = layer.load(1, {shade: [0.1, '#fff']});
        $.get('{:url("cancel_aduit")}',{id:id},function (res) {
            layer.close(loading);
            if (res.code > 0) {
                layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                  $('#table').bootstrapTable('refresh');
                });
            } else {
                layer.msg(res.msg, {time: 1800, icon: 2});
            }
        });
    }
    function recharge(id) {
        $.get('{:url("get_user_amount")}',{user_id:id},function (res) {
            if(res.code>0){
                $("#edit_worker input").val('');
                $('#amount').val(res.amount.cash_balance);
                $('#user_id').val(res.amount.user_id);
                $('#operation_user_id').val(res.user.id);
                $('#username').val(res.amount.username);
                $("#edit_worker").modal('show');
            }else {
                return false;
            }
        });

    }
    $("#recharge_amount").keyup(function() {
        var regStrs = [
            ['^0(\\d+)$', '$1'], //禁止录入整数部分两位以上，但首位为0
            ['[^\\d\\.]+$', ''], //禁止录入任何非数字和点
            ['\\.(\\d?)\\.+', '.$1'], //禁止录入两个以上的点
            ['^(\\d+\\.\\d{2}).+', '$1'] //禁止录入小数点后两位以上
        ];
        var testNum = $(this).val();
        if (testNum) {
            for (i = 0; i < regStrs.length; i++) {
                var reg = new RegExp(regStrs[i][0]);
                if (reg.test(testNum)) {
                    layer.msg('输入金额有误',{time: 1800, icon: 2});
                    $(this).val('');
                }
            }
        }
    });
    $('#submit_updata').click(function () {
        var data = {};
        var t = $('#form1').serializeArray();
        $.each(t, function() {
            data[this.name] = this.value;
        });
        data[$('#username').attr('name')] =$('#username').val();
        $.post('{:url("recharge")}',data,function (res) {
            if(res.code>0){
                layer.msg(res.msg, {time: 1800, icon: 1}, function () {
                    $("#edit_worker").modal('hide');
                    $('#table').bootstrapTable('refresh');
                });
            }else {
                layer.msg(res.msg, {time: 1800, icon: 2});

            }
        });
    });
</script>
</html>